Page({
  data: {
    userName: "CZC",
    deviceList: [
      {
        name: "ROBOT",
        icon: "/images/robot_icon.png"
      },
      {
        name: "石头G20",
        icon: "/images/stoner_icon.png"
      },
      {
        name: "iRobot i7+",
        icon: "/images/irobot_icon.png"
      },
      {
        name: "Roomba s9",
        icon: "/images/roomba_icon.png"
      }
    ],selectedIndex: null
  },
  selectDevice(e) {
    const index = e.currentTarget.dataset.index;
    this.setData({ selectedIndex: index });
    // 这里保留你原来的设备选择逻辑
    const device = e.currentTarget.dataset.device;
    console.log('选中设备:', device);
  },
  confirmSelection() {
    if (this.data.selectedIndex === null) {
      wx.showToast({
        title: '请先选择设备',
        icon: 'none',
        duration: 2000
      });
      return;
    }
  
    const selectedDevice = this.data.deviceList[this.data.selectedIndex];
    wx.navigateTo({
      url: `/pages/device-detail/device-detail?device=${encodeURIComponent(JSON.stringify(selectedDevice))}`,
    });
  }
  })
